﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.Model;
using Aij1.Utils;
using DevExpress.Web.ASPxTreeList;
using Aij1.BLL;

namespace Aij1.Cms
{
    public partial class MenuMan : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BtnAddTop.Visible = ASPxTreeList1.Nodes.Count == 0;
        }

        int menuType;
        protected void Page_Init(object sender, EventArgs e)
        {
            XpoDataSource1.Session = XpoSession;
            menuType = CommOp.ToInt(Request["T"]);
            XpoDataSource1.TypeName = menuType == 0 ? typeof(P_MgrMenu).FullName : typeof(P_ClientMenu).FullName;

            ASPxTreeList1.Columns["colEditSpecial"].Visible = menuType != 0;
            ASPxTreeList1.Columns["colPos"].Visible = menuType != 0;

            TreeListComboBoxColumn col = ASPxTreeList1.Columns["colPos"] as TreeListComboBoxColumn;
            col.PropertiesComboBox.DataSource = CategoryData.GetTypes<MenuPositionType>();
        }

        protected void ASPxTreeList1_NodeValidating(object sender, DevExpress.Web.ASPxTreeList.TreeListNodeValidationEventArgs e)
        {
            if (String.IsNullOrEmpty(CommOp.ToStr(e.NewValues["Title"])))
            {
                e.NodeError = "标题不能为空！";
            }
        }
    }
}